#include <stdio.h>
#include <stdlib.h>

struct Node {
	int x;
	Node *next;
};

struct AdjList {
	Node *first;
	Node *last;
	int size;
};

void
init(struct AdjList *adjList)
{
	adjList->size = 0;
	adjList->first = adjList->last = NULL;
}

void
pushback(struct AdjList *al, int x)
{
	struct Node *newnode;

	newnode = (struct Node *) malloc(sizeof(Node));
	newnode->x = x;
	newnode->next = NULL;
	if (!al->first)
		al->first = newnode;
	else
		al->last->next = newnode;
	al->last = newnode;
	al->size++;
}

void
free_al(struct AdjList *al)
{
	struct Node *n, *p;
	p = n = al->first;
	while (n) {
		n = n->next;
		free(p);
		p = n;
	}
}

void
listprint(struct Node *node)
{
	while (node) {
		printf("%d%s", node->x + 1, node->next ? " " : "\n");
		node = node->next;
	}
}

int
main(void)
{
	int AM[100][100];
	int n;
	int i=0, j=0;
	struct AdjList AL[100];

	freopen("adjlists.in", "r", stdin);
	freopen("adjlists.out","w",stdout);
	scanf("%d", &n);
	while (i < n) {
		j=0;
		while (j < n) {
			(void) scanf("%d", &AM[i][j++]);
		}
		i++;
	}
	i=j=0;
	while (i < n) {
		j = 0;
		init(&AL[i]);
		while (j < n) {
			if (AM[i][j])
				pushback(&AL[i], j);
			j++;
		}
		i++;
	}
	i=j=0;
	while (i < n) {
		printf("%d ", AL[i].size);
		if (AL[i].size)
			listprint(AL[i].first);
		else
			putchar('\n');
		free_al(&AL[i]);
		++i;
	}
	return 0;
}
